﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace ClimateControl.Controls.Converters
{
    public class BooleanToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BitmapImage image = null;

            if (!(value is bool))
                return image;

            string param = parameter as string;
            if (param == null || param.Length < 11)
               return image;

            string[] paramArray = param.Split('|');
            if (paramArray.Length != 2)
                return image;

            image = new BitmapImage(new Uri(string.Format(CultureInfo.CurrentCulture, @"/Images/{0}", paramArray[(bool)value ? 0 : 1]), UriKind.Relative));

            return image;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
 	        throw new NotImplementedException();
        }
    }
}
